package com.nbufe.config.task;

import com.nbufe.domain.entity.CarbonStatistics;
import com.nbufe.service.CarbonStatisticsService;
import com.nbufe.service.CarbonTradingService;
import com.nbufe.service.DataService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author luzhiheng
 * @Date 2024/3/7 16:51
 */
@Component
public class CarbonAssertTask {

    @Resource
    private DataService dataService;

    @Resource
    private CarbonStatisticsService carbonStatisticsService;

    @Resource
    private CarbonTradingService carbonTradingService;

    public void update() {

        Double totalCO2 = dataService.queryTotalCO2();
        List<CarbonStatistics> carbonStatisticsList = carbonStatisticsService.list();
        CarbonStatistics statistics = carbonStatisticsList.get(0);
        statistics.setCarbonEmission(totalCO2);
        Double totalCcer = carbonTradingService.queryTotalCCER();
        Double totalQuota = carbonTradingService.queryTotalQuota();
        statistics.setTotalCcer(totalCcer);
        statistics.setTotalQuota(totalQuota);
        carbonStatisticsService.updateById(statistics);
    }
}
